/*
Program Description: Maze game using asm and C++
Author:Joshua Kadletz
Date Created: 5/9/12
Last Modification Date: 5/9/12
*/

#include<iostream>
#include<iomanip>
#include<Windows.h>
#include<string>
#include<cstdlib>
#include<string>
#include<fstream>
using namespace std;

//asm functions for the maze
extern "C" { 
			int _maze();
		}

void Credits();				//displays credits
void MazeInstructions();			//display the instructions for the game

int main()

{	
	//declare variables
	int Quit = 1;
	int score = 0;
	int menu;
	int save;
	string name = "EMPTY";

	//declare fstream variables	
	ifstream inData;
     ofstream outData;

	do

	{
		system("CLS");
		
		//main menu
		cout <<endl;
		cout <<"------------------------------------------- \n"; //create border
		cout <<"Main Menu";
		cout <<endl;
		cout <<"1 - Instructions\n";
		cout <<"2 - Play the maze (ASM)\n";
		cout <<"3 - Credits\n";
		cout <<"4 - Enter Player Name\n";
		cout <<"0 - Quit\n";
		cout <<"------------------------------------------- \n"; //create border
		cout <<endl;
		cout <<"\nEnter a command and press [ENTER] > ";
		cin >> menu;									//users choice

		//switch to handle the user input from the main menu
		switch(menu)
		{

			case 0:
				{
				Quit = 0;
				cout << endl;
				break;
				} //end case 0

			case 1:
				{
				MazeInstructions(); //display instructions
				break;
				} //end case 1

			case 2:
				{
				score = _maze(); //run asm function (main game loop)
				system("CLS");						//clears screen
				
				//outputs score to user
				cout <<name << "'s Score: "<< score;
				cout << endl;
				
				cout <<"Save score? 1 = Yes, 2 = N \n";
				cin >> save;

				//check to see if they want to save score
				if (save == 1)
				{
					//open text file to write to
					outData.open("Scores.txt");
					
					//save name and score to file
					outData << name << ": " << score;

					//close file
					outData.close();
				}
				system("pause");
				break;
				} //end case 2

			case 3:
				{
				Credits(); //display the credits
				break;
				} //end case 3

			case 4:
				{
				//get player name
				cout << "Please enter your first name (no spaces):";
				cin >> name;
				break;
				}

			default:
				{
				cout<<"\nPlease enter a 0, 1, 2, 3.\n\n";
				system("pause");
				}// end case default
		} //end switch

	}while(Quit != 0);		//end do while

	cout <<"Thanks for playing the maze game\n\n";
	system("pause");
	return 0;
} //end main()

//display the instructions
void MazeInstructions()

{
	//game instructions
	system("CLS"); //clear screen
	cout <<"------------------------------------------- \n"; //create border
	cout<<"Explore the area using W,A,S,D\n";
	cout <<"W - Up\n";
	cout <<"A - Left\n";
	cout <<"S - Down\n";
	cout <<"D - Right\n";
	cout <<"Go to the Red Squares to increase your score by 20 points\n";
	cout <<"Get to the green square to win and exit to the menu\n";
	cout <<"If you finish with a time less than 11500 you get 500 extra points\n";
	cout <<"If you finish with a time between 11500 and 12500 you get 200 extra points\n";
	cout <<"If you collect all the red box and finish with a time under 21500, you get 200 extra points\n";
	cout <<"Good Luck!\n\n";
	cout <<"------------------------------------------- \n"; //create border
	system("pause");
} //end MazeInstructions()

//display the credits
void Credits()

{
	//credits
	system("CLS");
	cout <<"------------------------------------------- \n"; //create border
	cout <<"This program was designed and coded by Joshua Kadletz\n";
	cout <<"using a combination of C++ and MASM\n";
	cout <<"12MAR-SG360-WCO-V2D1 Computer Organization and Assembly Language\n";
	cout <<"Westwood College 2012\n";
	cout <<"Thanks for Playing\n";
	cout <<"------------------------------------------- \n"; //create border
	system("pause");

} //end Credits()

